/*
 * 编辑标签
 * @Author: ljb
 * @Date: 2018-03-27 17:53:27
 * @Last Modified by: kanglin
 * @Last Modified time: 2018-08-14 15:59:48
 */
<template>
	<div class="v-admin-product-tag-edit">
		<Form
			ref="formValidate"
			:model="formValidate"
			:label-width="120"
			name="edit-form">

			<Form-item
				:label="$t('tag.name')"
				prop="name">
				<i-input
					v-model="formValidate.name"
					:placeholder="$t('tag.please_enter_name')"
					name="edit-name"
					type="text"/>
			</Form-item>

			<Form-item
				:label="$t('tag.english_name')"
				prop="const">
				<i-input
					v-model="formValidate.const"
					:placeholder="$t('tag.please_enter_name')"
					name="edit-name"
					type="text"/>
			</Form-item>

			<Form-item>
				<Button
					type="primary"
					@click="updateTag">
					{{ $t('common.submit') }}
				</Button>
			</Form-item>

		</Form>
	</div>
</template>

<script>

export default {
	name: 'TagEdit',
	props: {
		tagDetail: {
			type: Object,
			default() {
				return {};
			},
		},
	},
	data() {
		return {
			formValidate: {
				name: null,

				const: null,
			}, // 更新分类时的表单

		};
	},
	watch: {
		tagDetail() {
			if (this.tagDetail) {
				this.formValidate.name = this.tagDetail.name;
				this.formValidate.const = this.tagDetail.const;
			}
		},
	},
	methods: {

		/**
         * 更新产品标签信息
         * @return {undefined}
         */
		updateTag() {
			const param = {
				_method: 'PUT',

				name: this.formValidate.name,
				const: this.formValidate.const,
			};

			this.$emit('update', this.tagDetail.id, param);
		},

	},
};
</script>
